﻿///隐藏域
CKEDITOR.dialog.add('wfhidden', function (editor) {
    var controlPre = 'bwdf_hid_';
    return {
        title: editor.lang.hidden.title,
        wfhidden: null,
        minWidth: 350,
        minHeight: 110,
        onShow: function () {
            delete this.wfhidden;

            var editor = this.getParentEditor(),
				selection = editor.getSelection(),
				element = selection.getSelectedElement();

            if (element && element.data('cke-real-element-type') && element.data('cke-real-element-type') == 'wfhidden') {
                this.wfhidden = element;
                element = editor.restoreRealElement(this.wfhidden);
                this.setupContent(element);
                selection.selectElement(this.wfhidden);
            }
        },
        onOk: function () {
            var name = this.getValueOf('info', 'name'),
				editor = this.getParentEditor(),
				element = CKEDITOR.env.ie && !(CKEDITOR.document.$.documentMode >= 8) ?
					editor.document.createElement('<input name="' + CKEDITOR.tools.htmlEncode(name) + '">')
					: editor.document.createElement('input');

            element.setAttribute('type', 'hidden');
            this.commitContent(element);
            var fakeElement = editor.createFakeElement(element, 'cke_hidden', 'wfhidden');
            if (!this.wfhidden)
                editor.insertElement(fakeElement);
            else {
                fakeElement.replace(this.wfhidden);
                editor.getSelection().selectElement(fakeElement);
            }
            return true;
        },
        contents: [
			{
			    id: 'info',
			    label: editor.lang.hidden.title,
			    title: editor.lang.hidden.title,
			    elements: [
					{
					    id: 'name',
					    type: 'text',
					    label: "字段名称",
					    labelLayout: 'horizontal',
					    labelStyle: 'width:50px;',
					    inputStyle: 'width:250px;',
					    'default': '',
					    accessKey: 'N',
					    setup: function (element) {
					        if (element.getAttribute('name')) {
					            this.setValue(element.getAttribute('name').replace(controlPre, '') || '');
					        }
					    },
					    commit: function (element) {
					        if (this.getValue() && (checkName(this.getValue()) || element.getAttribute('name') == controlPre + this.getValue())) {
					            element.setAttribute('id', controlPre + this.getValue());
					            element.setAttribute('name', controlPre + this.getValue());
					            element.setAttribute('value', '$!tc.GetValue("' + this.getValue() + '")');
					        }
					        else {
					            if (!element.getAttribute('name')) {
					                element.remove();
					            }
					            alert("字段名称不能重复和不能空！！！");
					            throw "字段名称不能重复和不能空";
					        }
					    }
					},
					{
					    id: 'fname',
					    type: 'text',
					    label: "字段意义",
					    labelLayout: 'horizontal',
					    labelStyle: 'width:50px;',
					    inputStyle: 'width:250px;',
					    setup: function (element) {
					        this.setValue(element.getAttribute('fname') || '');
					    },
					    commit: function (element) {
					        element.setAttribute('fname', this.getValue() || '');
					    }
					},
					{
					    id: 'defaultvalue',
					    type: 'text',
					    label: '默认值',
					    labelStyle: 'width:50px;',
					    inputStyle: 'width:250px;',
					    labelLayout: 'horizontal',
					    setup: function (element) {
					        this.setValue(element.getAttribute('defaultvalue') || '');
					    },
					    commit: function (element) {
					        element.setAttribute('defaultvalue', this.getValue() || '');
					    }
					},
                    {
                        id: 'itemdatatype',
                        type: 'select',
                        label: '数据类型',
                        labelStyle: 'width:50px;',
                        inputStyle: 'width:250px;',
                        labelLayout: 'horizontal',
                        'default': 'String',
                        items: ItemDataType.Hidden,
                        setup: function (element) {
                            this.setValue(element.getAttribute('itemdatatype') || '');
                        },
                        commit: function (element) {
                            element.setAttribute('itemdatatype', this.getValue() || '');
                        }
                    }
				]
			}
		]
    };
});

